package cn.whut.glab.web;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.whut.glab.service.UserService;

/**
 * Servlet implementation class ChangePwServlet
 */
public class ChangePwServlet extends HttpServlet {
	UserService service=new UserService();

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setHeader("Content-type", "text/html;charset=UTF-8"); 
		request.setCharacterEncoding("utf-8");
		String userName=request.getParameter("userName");
		String password=request.getParameter("password");
		String password2=request.getParameter("password2");
		if(password.equals(password2)){
			try {
				service.changePassword(userName, password);
				response.sendRedirect("/GlabManager/main.jsp");
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}else{
			request.setAttribute("msg", "您两次输入的密码不一致");
			request.getRequestDispatcher("/ChangePw.jsp").forward(request, response);
		}
	}

}
